package com.longfor.dragonshard.controller.base;

import com.longfor.drogon.common.bean.LFResultBean;
import com.longfor.drogon.common.exception.LFBizException;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * @author chi.zhang
 * @version v1.0
 * @create 2017-12-11 上午11:17
 **/
@ControllerAdvice(annotations = {RestController.class})
public class ExceptionReaper {
    private org.slf4j.Logger logger = LoggerFactory.getLogger(ExceptionReaper.class);

    @ExceptionHandler(value = {LFBizException.class, RuntimeException.class})
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ResponseBody
    public LFResultBean exception(Exception exception) {
        exception.printStackTrace();
        LFResultBean<?> result = new LFResultBean();
        result.setMsg(exception.getMessage());
        result.setCode(LFResultBean.FAIL);
        return result;
    }


}
